package com.zz.schoolwall.service.impl;

import com.zz.common.utils.FileType;
import com.zz.common.utils.ShiroUtils;
import com.zz.schoolwall.dao.SchoolWallDao;
import com.zz.schoolwall.domain.SchoolWallDO;
import com.zz.schoolwall.domain.SchoolWallDTO;
import com.zz.schoolwall.domain.SchoolWallMediaDO;
import com.zz.schoolwall.service.SchoolWallMediaService;
import com.zz.schoolwall.service.SchoolWallService;
import com.zz.system.domain.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class  SchoolWallServiceImpl  implements SchoolWallService {

    @Autowired
    private SchoolWallDao schoolWallDao;
    @Autowired
    private SchoolWallMediaService schoolWallMediaService;

    @Override
    public int remove(Long wallId) {
        return schoolWallDao.deleteByPrimaryKey(wallId);
    }

    @Override
    public int save(SchoolWallDO record) {
        UserDO user= ShiroUtils.getUser();
        record.setWallUpdateman(user.getUserId()+"");
        record.setWallCreateman(user.getUserId()+"");
        return schoolWallDao.insertSelective(record);
    }

    @Override
    public SchoolWallDO get(Long wallId) {
        return schoolWallDao.selectByPrimaryKey(wallId);
    }

    @Override
    public List<SchoolWallDO> list(Map<String,Object> map) {
        return schoolWallDao.list(map);
    }
    @Override
    public int count(Map<String,Object> map) {
        return schoolWallDao.count(map);
    }

    @Override
    public int update(SchoolWallDO record) {
        return schoolWallDao.updateByPrimaryKeySelective(record);
    }
    @Override
    public int logicRemove(Long wallId) {
        return schoolWallDao.logicRemove(wallId);
    }
    @Override
    public int batchLogicRemove(Long[] wallIds) {
        return schoolWallDao.batchLogicRemove(wallIds);
    }

    @Override
    public int increaseLikeNum(Long wallId) {
        return schoolWallDao.increaseLikeNum(wallId);
    }

    @Override
    public int decreaseLikeNum(Long wallId) {
        return schoolWallDao.decreaseLikeNum(wallId);
    }

    @Override
    public int increaseCommentNum(Long wallId) {
        return schoolWallDao.increaseCommentNum(wallId);
    }

    @Override
    public int decreaseCommentNum(Long wallId) {
        return schoolWallDao.decreaseCommentNum(wallId);
    }

    public int save(SchoolWallDTO record) {
        int t=save((SchoolWallDO)record);
        String id=ShiroUtils.getUser().getUserId()+"";
        for(SchoolWallMediaDO media:record.getSysFileIds()){
            media.setWallId(record.getWallId());
            media.setMediaCreateman(id);
            media.setMediaType(""+FileType.fileType(media.getMediaUrl()));
            schoolWallMediaService.save(media);
        }
        return t;
    }
}